<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.javapig.util.*,com.dd.*,java.util.*"%>
<%@ include file="global.jsp"%>
<%
int caiGouBiaoId = ParamUtils.getIntParameter(request,"CaiGouBiaoId", -1);
if (caiGouBiaoId == -1){
	  out.println("参数错误");
    return ;
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>采购报价审核</title>
</head>
<body>
<%
	// 右边备注
	String youBianBeiZhu = ParamUtils.getParameter(request,"YouBianBeiZhu");
    if (youBianBeiZhu==null)
    	youBianBeiZhu = "";

	// 采购部意见
	String caiGouBuYiJian = ParamUtils.getParameter(request,
			"CaiGouBuYiJian");
	if (caiGouBuYiJian == null)
		caiGouBuYiJian="";

	// 中心经理意见
	String zhongXinJingLiYiJian = ParamUtils.getParameter(request,
			"ZhongXinJingLiYiJian");
	if (zhongXinJingLiYiJian==null)
		zhongXinJingLiYiJian="";
	
	// 分管总裁意见
	String fenGuanZongCaiYiJian = ParamUtils.getParameter(request,
			"FenGuanZongCaiYiJian");
	if (fenGuanZongCaiYiJian==null)
		fenGuanZongCaiYiJian = "";

    //项目组意见
    String xiangMuZuYiJian = ParamUtils.getParameter(request,"XiangMuZuYiJian");
    if (xiangMuZuYiJian == null)
    	xiangMuZuYiJian="";
    
	// 下面备注
	String xiaMianBeiZhu = ParamUtils.getParameter(request,
			"XiaMianBeiZhu");
	if (xiaMianBeiZhu == null)
		xiaMianBeiZhu = "";

	//	 比价意见
	String biJiaBuYiJian = ParamUtils.getParameter(request,
	"BiJiaBuYiJian");
	if (biJiaBuYiJian == null)
		biJiaBuYiJian = "";
	//缀加审核者信息
	biJiaBuYiJian = biJiaBuYiJian + "<$shenhe="+pageUser.getXingMing()+"$>";
	
    //采购报价表
    CaiGouBiaoJia cgbj = new CaiGouBiaoJia(caiGouBiaoId);
    cgbj.setYouBianBeiZhu(youBianBeiZhu);
	cgbj.setXiaMianBeiZhu(xiaMianBeiZhu);
	boolean result;
	//..................................................
	//比价部
	if (pageUser.isBiJiaBu()) {
		//CaiGouBiaoJia cgbj = new CaiGouBiaoJia(caiGouBiaoId);		
		ArrayList sps = cgbj.GetCaiGouShangPings();
        ArrayList cggss = cgbj.GetCaiGouGongSis();
		//厂商数
		int i_factorys = cggss.size();
		//商品数
		int i_products = sps.size();

		//厂商和产品审核价数组
		float[][] prod_comp_sj = new float[i_products][i_factorys];

		//审核价总价
		String[] zj_sj = new String[i_factorys];

		System.out.println("bj 产品和厂商报价区");
		for (int i = 0; i < i_products; i++) {
			for (int j = 0; j < i_factorys; j++) {
		String id_sj = "sj" + (i + 1) + "_" + (j + 1);
		prod_comp_sj[i][j] = new Float(ParamUtils.getFloatParameter(
				request, id_sj, 0.0f)).floatValue();
		System.out.println(id_sj + "=" + prod_comp_sj[i][j]);
			}
		}

		System.out.println("zj 厂家报价总价");
		for (int i = 0; i < i_factorys; i++) {
			String id_sj = "sjzj_" + (i + 1);
			zj_sj[i] = ParamUtils.getParameter(request, id_sj);
			System.out.println(id_sj + "=" + zj_sj[i]);
		}
		
		cgbj.setBiJiaBuYiJian(biJiaBuYiJian);
		System.out.println(biJiaBuYiJian);
		//循环		

		Iterator iter = sps.iterator();
		int i = 1;
		while (iter.hasNext()) {
			//更新审核价
			CaiGouShangPing sp = (CaiGouShangPing) iter.next();
			int caiGouShangPingId = sp.getCaiGouShangPingId();
			Iterator iter_gs = cggss.iterator();
			int j = 1;
			while (iter_gs.hasNext()) {
		       CaiGouGongSi val = (CaiGouGongSi) iter_gs.next();
		       int caiGougGongSiId = val.getGongSiId();
		       String idLabel = "sj"+i+"_"+j;
		       float temp = ParamUtils.getFloatParameter(request,idLabel, 0.0f);
		       System.out.println(idLabel+":"+temp);
		       cgbj.updateShenHeBaoJia(caiGouShangPingId, caiGougGongSiId, temp);

		       j++;
			}
			i++;
		}
		//更新审核总价
		Iterator iter_gs = cggss.iterator();
		int j = 1;
		while (iter_gs.hasNext()) {   
	       CaiGouGongSi cggs_temp = (CaiGouGongSi) iter_gs.next();
	       String idLabel = "sjzj_"+j;
	       float temp = ParamUtils.getFloatParameter(request,idLabel, 0.0f);
	       cggs_temp.setZongShenHeBaoJia(temp);
	       cggs_temp.UpdateGongSi();
	       j++;
	    }
		//cgbj.setBiaoZhuangTai(SysGlobals.SH_STATE_TJ);
		result = cgbj.UpdateCaiGouBiaoJiaDan();
		
	}
	//..................................................
	//采购组
	else if (pageUser.isCaiGouBu()) {
		//缀加审核者信息
		caiGouBuYiJian = caiGouBuYiJian + "<$shenhe="+pageUser.getXingMing()+"$>";		
		cgbj.setCaiGouBuYiJian(caiGouBuYiJian);
		result = cgbj.UpdateCaiGouBiaoJiaDan();
	}
	//..................................................
	//项目组
	else if (pageUser.isXiangMuZu()) {
		//缀加审核者信息
		xiangMuZuYiJian = xiangMuZuYiJian + "<$shenhe="+pageUser.getXingMing()+"$>";
		cgbj.setXiangMuZouYiJian(xiangMuZuYiJian);
		result = cgbj.UpdateCaiGouBiaoJiaDan();
	}
	//..................................................
	//经理
	else if (pageUser.isJingLi()) {
		//缀加审核者信息
		zhongXinJingLiYiJian = zhongXinJingLiYiJian + "<$shenhe="+pageUser.getXingMing()+"$>";
		cgbj.setZhongXinJingLiYiJian(zhongXinJingLiYiJian);
		String sub_type = ParamUtils.getParameter(request,"Submit");
		if ("结束审批".equals(sub_type))
		   cgbj.setBiaoZhuangTai(SysGlobals.SH_STATE_TJ);
		result = cgbj.UpdateCaiGouBiaoJiaDan();

	}
	//..................................................
	//总裁
	else if (pageUser.isZhongCai()) {
		//缀加审核者信息
		fenGuanZongCaiYiJian = fenGuanZongCaiYiJian + "<$shenhe="+pageUser.getXingMing()+"$>";		
		cgbj.setFenGuanZongCaiYiJian(fenGuanZongCaiYiJian);
		String sub_type = ParamUtils.getParameter(request,"Submit");
		if ("同意".equals(sub_type))
			cgbj.setBiaoZhuangTai(SysGlobals.SH_STATE_TJ);
		else if("拒绝".equals(sub_type))
		    cgbj.setBiaoZhuangTai(SysGlobals.SH_STATE_JJ);
		result = cgbj.UpdateCaiGouBiaoJiaDan();
	} else {
		//不是审核员，采购员，可以更新技术
		result = cgbj.UpdateCaiGouBiaoJiaDan();

	}

	//采购报价
	/*

	 
	 //执行数据库操作
	 boolean res = cgbj.InsertCaiGouBiaoJiaDan();
	 if (res){
	 response.sendRedirect("comm_user.jsp");
	 }*/
	 if (result){
		 System.out.println("执行OK");
		 response.sendRedirect("sh_cgbj.jsp?CaiGouBiaoId="+caiGouBiaoId);
	 }
	 else
		 System.out.println("执行 not OK");
%>
</body>
</html>
